<?php

class ControllerWpPost extends Controller
{
    private $error = array();

    public function mySubscriptions()
    {
        $this->load->model('wp/post');
        if (! $this->actionCheck(true, false)) {
            return;
        }
        
		
		$data = $this->model_wp_post->getMySubscriptions( $this->customer->getId(),
					$this->request->get['pageNum'],$this->request->get['pageSize']);

        $this->load->model('tool/image');
        foreach ($data as &$item){
            $customer_subscription = $this->db->query("select DISTINCT * from customer_subscription where customer_id = '".(int)$this->customer->getId()."' and post_id = '".(int)$item['ID']."' ")->row;
            if($customer_subscription){
                $item['read'] = 1;
            }else{
                $item['read'] = 0;
            }
            if(empty($item['thumb'])){
                $item['thumb'] = HTTP_IMAGE . 'image/' . 'no_image.png';//$this->model_tool_image->resize('no_image.png', 100, 100);
            }
            else{
                $item['thumb'] = HTTP_IMAGE . 'image/' . $item['thumb'] ;// $this->model_tool_image->resize($item['thumb'], 100, 100);
            }

        }

		$this->response->setOK( $data);
    }



	public function Subscription()
    {
        $this->load->model('wp/post');
        if (! $this->actionCheck(true, false)) {
            return;
        }
        
		
		$data = $this->model_wp_post->getSubscription($this->customer->getId(),$this->request->get['id']);

        $customer_subscription = $this->db->query("select * from customer_subscription where post_id = '".$this->request->get['id']."' and customer_id = '".(int)$this->customer->getId()."'")->row;
        if(!$customer_subscription){
            $this->db->query("insert into customer_subscription SET post_id = '".$this->request->get['id']."',customer_id = '".(int)$this->customer->getId()."' ");
        }

		$this->response->setOK( $data);
		
    }
	
	public function Comment()
    {
        $this->load->model('wp/post');
        if (! $this->actionCheck(true, true)) {
            return;
        }
        
		
		$this->model_wp_post->comment($this->request->post['post_id'],$this->request->post['message'],
				$this->customer->getId(),$this->customer->getFirstName());
		$this->response->setOK( );
		
    }

    public  function getTop4Posts(){
        $this->load->model('wp/post');
        if (! $this->actionCheck(true, false)) {
            return;
        }


        $data = $this->model_wp_post->getTop4Posts($this->customer->getId());
        $this->response->setOK( $data);
    }
    public  function birthday_push(){
        $this->load->model('wp/post');
        if (! $this->actionCheck(false, false)) {
            return;
        }


        $this->model_wp_post->birthday_push();
        $this->response->setOK( );

    }
}